package org.springextensions.actionscript.mvcs.service.operation
{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.net.URLRequest;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	
	import org.springextensions.actionscript.mvcs.command.NullFileLoadCompleteCommand;

	public class LibraryFileLoadOperation extends LoaderOperation
	{
		override public function get loaderContext():LoaderContext
		{
			return new LoaderContext(false, ApplicationDomain.currentDomain);
		}
		
		override public function execute():void
		{
			_loader = new Loader();
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
			_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, handleError);
			_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, dispatchProgress);
			//_loader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, handleError);
			
			var context:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
			trace("CUrrent domain? " + (context.applicationDomain == ApplicationDomain.currentDomain));
			_loader.load(new URLRequest(url), context);
		}
		
		public function LibraryFileLoadOperation()
		{
			super(new NullFileLoadCompleteCommand());
		}
		
	}
}